﻿using System;
using System.Web.Mvc.Html;
using ControleRepresentante.Logic.Models;

namespace WebSite.ViewModels.IndexViewModels
{
    public static class UsuarioIndexColumns
    {
        public static Guid Username = new Guid("13140ec9-23ac-4ce7-8fe3-efd9bc4d4a4e");
        public static Guid Email = new Guid("f625b6be-fe57-4a1a-b20d-5ef284ef45e2");
        public static Guid Ativo = new Guid("8d64a8a0-2a3f-427d-a2a7-3048c187a99d");
    }

    public class UsuarioIndexViewModel : IndexViewModel<User>
    {
        private readonly User m_CurrentUser;

        public UsuarioIndexViewModel(User currentUser)
            : base("Usuários")
        {
            m_CurrentUser = currentUser;
        }

        protected override void RegisterColumns(IndexColumnDefinitionsCollectionWrapper<User> indexColumnDefinitionsCollectionWrapper)
        {
            indexColumnDefinitionsCollectionWrapper.Register(UsuarioIndexColumns.Username, (user, htmlHelper) => user.Id == m_CurrentUser.Id ? user.Username : htmlHelper.ActionLink(user.Username, "Details", new { id = user.Id }).ToHtmlString());
            indexColumnDefinitionsCollectionWrapper.Register(UsuarioIndexColumns.Email, x => x.Email);
            indexColumnDefinitionsCollectionWrapper.Register(UsuarioIndexColumns.Ativo, x => x.Ativo);
        }

        protected override bool CanEditSpecific(User modelBase)
        {
            return base.CanEditSpecific(modelBase) && modelBase.Id != m_CurrentUser.Id;
        }

        protected override bool CanDeleteSpecific(User modelBase)
        {
            return base.CanDeleteSpecific(modelBase) && modelBase.Id != m_CurrentUser.Id;
        }
    }
}